package com.lei.chinese_herbal_medicine.Util;

import com.lei.chinese_herbal_medicine.Entity.Flow;

import java.text.SimpleDateFormat;
import java.util.*;

public class DataAnalysis {
    public static Map analysisFlows(List<Flow> flows){
        Map map=new HashMap();
        Map<String,Integer> count=new HashMap();
        Map<String,Integer> good=new HashMap();
        Map<String,Integer> ordinary=new HashMap();
        Map<String,Integer> bad=new HashMap();
        SimpleDateFormat format = new SimpleDateFormat("MM-dd");
        SimpleDateFormat year = new SimpleDateFormat("yyyy");
        String nowYear=year.format(new Date());
        List<String> years=new ArrayList<>();
        for (Flow flow : flows) {
            Date date=flow.getDate();
            String flowYear=year.format(date);
            if(nowYear.equals(flowYear)){//今年的流量
                String key=format.format(date);
                years.add(key);
            }
        }
        for (String s : years) {
            count.put(s,0);
            good.put(s,0);
            ordinary.put(s,0);
            bad.put(s,0);
        }
        for (Flow flow : flows) {
            Date date=flow.getDate();
            String flowYear=year.format(date);
            if(nowYear.equals(flowYear)){//今年的流量
                String key=format.format(date);
                count.put(key,count.get(key)+1);
                if(flow.getAttitude()!=null){
                    Float score=flow.getAttitude();
                    if(score>=3.5){
                        good.put(key,good.get(key)+1);
                    }else if(score>=2.5){
                        ordinary.put(key,ordinary.get(key)+1);
                    }else{
                        bad.put(key,bad.get(key)+1);
                    }
                }
            }
        }
        for (String s : years) {
            Map m=new HashMap();
            m.put("count",count.get(s));
            m.put("good",good.get(s));
            m.put("ordinary",ordinary.get(s));
            m.put("bad",bad.get(s));
            map.put(s,m);
        }
        return map;
    }
}
